<?php
namespace app\controller;

use think\Request;
use app\controller\Base;
use app\common\UtilService;
use app\model\EaWxSite;
use app\model\EaWxPrograms;

class Programs extends Base
{
    /**
     * [index 首页]
     * @since  2025-06-04
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function index(Request $request)
    {
    	$param = UtilService::getMore([
    		['page', 1],
    		['pageSize', 28],
            ['type', ''], // 对应字段：type2
    	]);

    	$arrs = [];

        # 小程序分类
        $arrs['type_list'] = EaWxPrograms::programsGroupName();

        # 最热
        $arrs['new_programs'] = EaWxPrograms::field('*')->where('status', 1)->order('views DESC')->limit(10)->cache(600)->select()->toArray();

        $arrs['list'] = EaWxPrograms::getProgramsList($param);
        
        // dump($arrs);exit;

        return view('index', compact('arrs', 'param'));
    }

    /**
     * [info 详细]
     * @since  2025-06-11
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function info(Request $request)
    {
    	$param = UtilService::getMore([
    		['id', ''],
    	]);

        $info = EaWxPrograms::where('id', $param['id'])->find();
        $info->views = $info['views'] + 1;
        $info->save();

    	# 网站分类
        $arrs['type_list'] = EaWxPrograms::programsGroupName();

        # 最热
        $arrs['new_programs'] = EaWxPrograms::field('*')->where('status', 1)->order('views DESC')->limit(10)->cache(600)->select()->toArray();

        # 下一个 5
        $xia = EaWxPrograms::field('id, name')->where('id', '>', $param['id'])->order('id ASC')->limit(1)->cache(120)->find();

        # 上一个 5
        $shang = EaWxPrograms::field('id, name')->where('id', '<', $param['id'])->order('id DESC')->limit(1)->cache(120)->find();

        return view('info', compact('info', 'arrs', 'xia', 'shang'));
    }
}
